﻿import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")

from System import *
from System.Windows.Forms import *
from System.Drawing import *

def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        return False	    
	    
def TimerComplete(sender, args):
    sender.Stop()
    g = globals()
    g["TimerList"].Items.Remove(sender.Tag)
    MessageBox.Show(sender.Tag + " : Completed!")
    
def cButtonClicked(sender, args):
   t = Timer()
   g = globals()
   tname = g["MainWindow"].Controls["ContentTabs"].Controls["ExampleTab"].Controls["TimerNameBox"].Text
   seconds = g["MainWindow"].Controls["ContentTabs"].Controls["ExampleTab"].Controls["SecondsBox"].Text
   mins = g["MainWindow"].Controls["ContentTabs"].Controls["ExampleTab"].Controls["MinBox"].Text
   hours = g["MainWindow"].Controls["ContentTabs"].Controls["ExampleTab"].Controls["HourBox"].Text
   if not is_number(seconds):
	    seconds = 0
	    
   if not is_number(mins):
        mins = 0
      
   if not is_number(hours):
	    hours = 0
 
   t.Tag = tname
   t.Interval  = (int(seconds)*1000) + (int(mins)*60000) + (int(hours)*360000)
   t.Tick += TimerComplete
   t.Start()
   g["TimerList"].Items.Add(tname)
   
def sButtonClicked(sender, args):
   g = globals()
   g["MainWindow"].Controls["ContentTabs"].Controls["ExampleTab"].Dispose()
    
g = globals()
g["TimerList"] = ListBox()
g["TimerList"].Location = Point(300, 50)
g["TimerList"].Width = 150
g["TimerList"].Size = Size(370, 500) 	
 
timerLabel = Label()
timerLabel.Location = Point(450,30)
timerLabel.Text = "Active Timers"

tBox = TextBox()
tBox.Location = Point(10, 20)
tBox.Text = "Enter Timer Name To Delay"
tBox.Width = 130
tBox.Name = "TimerNameBox"

tBoxLabel = Label()
tBoxLabel.Location = Point(140, 20)
tBoxLabel.Text = "TimerName"
tBoxLabel.Width = 150

sBox = TextBox()
sBox.Location = Point(10, 60)
sBox.Text = "1"
sBox.Width = 130
sBox.Name = "SecondsBox"

sBoxLabel = Label()
sBoxLabel.Location = Point(140, 60)
sBoxLabel.Text = "Time In Seconds.."
sBoxLabel.Width = 150

mBox = TextBox()
mBox.Location = Point(10, 80)
mBox.Text = "0"
mBox.Width = 130
mBox.Name = "MinBox"

mBoxLabel = Label()
mBoxLabel.Location = Point(140, 80)
mBoxLabel.Text = "Time In Minuites"
mBoxLabel.Width = 150

hBox = TextBox()
hBox.Location = Point(10, 100)
hBox.Text = "0"
hBox.Width = 130
hBox.Name = "HourBox"

hBoxLabel = Label()
hBoxLabel.Location = Point(140, 100)
hBoxLabel.Text = "Time In Hours.."
hBoxLabel.Width = 150

cButton = Button()
cButton.Location = Point(10, 120)
cButton.Click += cButtonClicked
cButton.Text = "Start Timer"
cButton.Width = 100

sButton = Button()
sButton.Location = Point(10, 500)
sButton.Click += sButtonClicked
sButton.Text = "Close"
sButton.Width = 100

tab = TabPage()
tab.Text = "Timer"
tab.Name = "ExampleTab"
tab.Controls.Add(cButton)
tab.Controls.Add(tBox)
tab.Controls.Add(tBoxLabel)
tab.Controls.Add(sBox)
tab.Controls.Add(sBoxLabel)
tab.Controls.Add(hBox)
tab.Controls.Add(hBoxLabel)
tab.Controls.Add(mBox)
tab.Controls.Add(mBoxLabel)
tab.Controls.Add(sButton)
tab.Controls.Add(g["TimerList"])
tab.Controls.Add(timerLabel)

g["MainWindow"].Controls["ContentTabs"].Controls.Add(tab)


